<?

//Data loading

$pdf=new COAPDFReport("P","mm","Letter");
$pdf->DBConnection($DBConnection->dbc);
$pdf->AddFont('arialn','','arialn.php');
$pdf->SetFont('arialn','',10);
$pdf->AddPage();
$pdf->GenerateReport();
$pdf->Output();

class COAPDFReport extends PDF {
/**
  function COAPDFReport($Page,$Size,$PageMode) {
    parent::PDF($Page,$Size,$PageMode);
    $this->Title = "DAFTAR PPN MASUKAN";
    $this->Perush = (GetParam("office",""))?GetCompany (GetParam("office","")):'PT. AMPEL TRAINING';
    $this->Page = "PAGE";

    $this->RowColumnSize = array(5,60,30,20,25,10,35);
    $this->RowBorder = array("","","","","","","");
    $this->TableName = "idms_ais_process.view_faktur_no";
    $this->AddFont('arialn','','arialn.php');
    $this->SetFont('arialn','',10);
  }**/

  function Header() {
	$this->Title = "DAFTAR PPN MASUKAN";
	$this->Perush = (GetParam("office",""))?GetCompany (GetParam("office","")):'PT. AMPEL JAYA';
  
  
   global $DBGeneral;
        $SQL = "SELECT * FROM $DBGeneral.tblcompany ";
        $CompanyResult = $this->DBConnection->get_row($SQL);

        $NPWPString  = substr($CompanyResult->pakwtnpwp,0,2).".".substr($CompanyResult->pakwtnpwp,2,3);
        $NPWPString .= ".".substr($CompanyResult->pakwtnpwp,5,3).".".substr($CompanyResult->pakwtnpwp,8,1).".".substr($CompanyResult->pakwtnpwp,9,3).".".substr($CompanyResult->pakwtnpwp,12,3);
	
    //Header Configuration
    $this->HeaderAttribute[0]["M"] = array($this->Title);
    $this->HeaderAttribute[0]["C"] = array(195);
    $this->HeaderAttribute[0]["O"] = array("C");
/*
    $this->HeaderAttribute[1]["M"] = array($this->Perush);
    $this->HeaderAttribute[1]["C"] = array(195);
    $this->HeaderAttribute[1]["O"] = array("C");
*/
    $this->HeaderAttribute[2]["M"] = array("PERIODE : ".GetParam("fromDate","")." S/D ".GetParam("toDate",""));
    $this->HeaderAttribute[2]["C"] = array(195);
    $this->HeaderAttribute[2]["O"] = array("C");

    $this->HeaderAttribute[3]["M"] = array("PKP : ".$this->Perush,"","N.P.W.P : ".$NPWPString);
    $this->HeaderAttribute[3]["C"] = array(60,75,60);
    $this->HeaderAttribute[3]["B"] = array("LT","T","RT");

    $this->HeaderAttribute[4]["M"] = array("","PKP.".$NPWPString);
    $this->HeaderAttribute[4]["C"] = array(135,60);
    $this->HeaderAttribute[4]["B"] = array("LB","RB");

    $this->HeaderAttribute[5]["M"] = array("NAMA PKP PENJUAL BKP");
    $this->HeaderAttribute[5]["C"] = array(195);
    $this->HeaderAttribute[5]["B"] = array("LR");

    $this->HeaderAttribute[6]["M"] = array("PEMBERI JKP/BANK DEVISA","NPWP","NO. SERI FP","TGL. FP/SSP","PPN (Rp)","KET");
    $this->HeaderAttribute[6]["C"] = array(60,30,50,20,25,10);
    $this->HeaderAttribute[6]["O"] = array("","C","","","","");
    $this->HeaderAttribute[6]["B"] = array("L","","","","","R");

    $this->HeaderAttribute[7]["M"] = array("DITJEN BEA DAN CUKAI","","NOMOR PIUD","","(A)","");
    $this->HeaderAttribute[7]["C"] = array(60,30,50,20,25,10);
    $this->HeaderAttribute[7]["B"] = array("LB","B","B","B","B","RB");

    $this->WriteLine($this->HeaderAttribute);
  }

  function DBConnection ($Conn) {
    $this->DBConnection = $Conn;
  }

  function GenerateReport(){
		$this->RowColumnSize = array(5,60,30,20,25,10,35);
		$this->TableName = "view_faktur_no";
      $SQL = "
                            SELECT *, date_format(tglbkt,'%d/%m/%y') as tgl
              FROM {$this->TableName}
              WHERE skada like '".GetPPNSkada()."'
             ";
      list($day,$month,$year) = explode("/",GetParam("fromDate",""));
      $FDate = "$year-$month-$day";
      list($day,$month,$year) = explode("/",GetParam("toDate",""));
      $TDate = "$year-$month-$day";
      $SQL .= " AND tglbkt >= '$FDate' AND tglbkt<='$TDate' ";
      $SQL .= " ORDER BY vat, nobkt, tglbkt";
      $MyResult = $this->DBConnection->get_results($SQL,ARRAY_A);
      //die($SQL);
      $n=0;
      if ($MyResult)
      foreach ($MyResult as $RowResult) {
        $Records[$n]["M"][] = $n+1;
        $Records[$n]["M"][] = $RowResult["debnam"];
        $Records[$n]["M"][] = $RowResult["npwp"];
        $Records[$n]["M"][] = "";
        $Records[$n]["M"][] = "";
        $Records[$n]["M"][] = "";
        $Records[$n]["M"][] = "";
        $Records[$n]["C"] = $this->RowColumnSize;
        $Records[$n]["B"] = array("L","","","","","R");
        $n++;
      }
      $this->WriteLine($Records);
  }

  function WriteLine($Results) {
    foreach ($Results as $Line) {
      for ($x=0;$x<count($Line["M"]);$x++) {
      if (count($Line["M"]))
        $this->Cell($Line["C"][$x],5,$Line["M"][$x],$Line["B"][$x],0,$Line["O"][$x],0);
      }
      if (count($Line["M"]))
      $this->Ln();
    }
  }

/*
  function WriteLine($Results) {
    for ($y=0;$y<count($Results);$y++) {
      for ($x=0;$x<count($Results[$y]["M"]);$x++) {
      if (count($Results[$y]["M"]))
        $this->Cell($Results[$y]["C"][$x],5,$Results[$y]["M"][$x],$Results[$y]["B"][$x],0,$Results[$y]["O"][$x],0);
      }
      if (count($Results[$y]["M"]))
      $this->Ln();
    }
  }
*/
  function BlankLine() {

  }

    function ReportTable($Result) {
        
        //Column widths
        global $DBConnection;
        $w=array(15,30,60,20,25,10,35);
        //Data
        $SQL = "SELECT taxprefix FROM tblprofile ";
        $TaxPrefix = $DBConnection->dbc->get_var($SQL);

      $ShowSubtotalSederhana = 1;
        foreach($Result as $row)
        {
        $rownumber++;
        $this->Cell(5,5,$rownumber.".",0,0,'R');
            $this->Cell($w[0]+$w[1],5,$row["debnam"],0,0,'L');
            $this->Cell($w[2],5,$row["npwp"],0,0,'C');
            $this->Cell($w[3],5,"",0,0,'L');
            $this->Cell($w[4],5,$row["tglbkt"],0,0,'C');
            $this->Cell($w[5],5,FormatNumber($row["jumlah"]),0,0,'R');
        $this->Cell($w[6],5,"",0,0,'C');
        $this->Ln();
        }
      $this->Ln();
      $this->Cell($w[0]+$w[1],5,"",0,0,'L');
      $this->Cell($w[2],5,"Total Faktur Pajak Standar",0,0,'L');
      $this->Cell(3,5,":",0,0,'L');
      $this->Cell($w[3],5,FormatNumber($Subtotal),"TB",0,'R');
      $this->Ln();
        $GrandTotal = $Subtotal + $SubtotalSederhana;
      $this->Cell($w[0]+$w[1],5,"",0,0,'L');
      $this->Cell($w[2],5,"Total Seluruh",0,0,'L');
      $this->Cell(3,5,":",0,0,'L');
      $this->Cell($w[3],5,FormatNumber($GrandTotal),"TB",0,'R');
      $this->Ln();
      $this->Ln();
      $this->Ln();
      $this->Ln();
            $this->Cell($w[0]+$w[1],5,"Pemeriksa",0,0,'C');
      $this->Ln();
      $this->Ln();
      $this->Ln();
      $this->Ln();
            $this->Cell($w[0]+$w[1],5,"( ......................................... )",0,0,'C');
        //Closure line
        //$this->Cell(array_sum($w),0,'','T');
    }

    function Footer() {
        //Closure line
//      $this->Cell(195,0,'','T');
    }

}


?>
